package com.msb.mall.product.controller;


import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;
import com.msb.mall.product.entity.SpuInfoEntity;
import com.msb.mall.product.entity.vo.OrderItemSpuInfoVo;
import com.msb.mall.product.entity.vo.SpuInfoVo;
import com.msb.mall.product.service.SpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * spu信息
 *
 * @author lwq
 * @email 1907326957@qq.com
 * @date 2024-06-12 21:28:32
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;


    /**
     * 商品上架
     * 传递spuId
     * 根据spuId 查询出数据 存储在es 中
     * 修改spuId的状态为上架
     */
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable("spuId") Long spuId ){
//        PageUtils page = spuInfoService.queryPage(params);
        spuInfoService.spuUp(spuId);
        return R.ok();
    }
    /**
     * 列表
     */
    @RequestMapping("/getOrderItemSpuBySpuId/{spuIds}")
    public List<OrderItemSpuInfoVo> getOrderItemSpuBySpuId(@PathVariable("spuIds") Long[] spuIds){
        return spuInfoService.getOrderItemSpuBySpuId(spuIds);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = spuInfoService.queryPage(params);
        PageUtils page = spuInfoService.queryPageByCondition(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SpuInfoVo vo){
//		spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(vo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
